package de.ralbus.stellplatz.funktionen;

import de.ralbus.stellplatz.R;
import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class FavoritenCursorAdapter extends SimpleCursorAdapter{
	
	public FavoritenCursorAdapter(Context context, Cursor c) {
		super(context, R.layout.rowlayout, c, new String[] {"_id"},	new int[] {android.R.id.text1} );
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		super.bindView(view, context, cursor);
		
		//showToast("cursor gestartet");      
		int ColumnOrt = cursor.getColumnIndex("ort");
		int ColumnBeschreibung = cursor.getColumnIndex("beschreibung");		
		int ColumnStrom = cursor.getColumnIndex("strom");	
		int ColumnPreis = cursor.getColumnIndex("preis");
		int ColumnWasser = cursor.getColumnIndex("wasser");
		int ColumnWc = cursor.getColumnIndex("wc");	
		int ColumnChemie = cursor.getColumnIndex("vz");	
		int ColumnDusche = cursor.getColumnIndex("dusche");	
		
		TextView textview1 = (TextView) view.findViewById(R.id.label);
		textview1.setText(cursor.getString(ColumnBeschreibung));
		
		TextView textview2 = (TextView) view.findViewById(R.id.label1);
		textview2.setText(cursor.getString(ColumnOrt));
		
		if (cursor.getString(ColumnStrom) != null) {

			if (cursor.getString(ColumnStrom).equals("1")) {
				ImageView strom = (ImageView) view.findViewById(R.id.icon_1);
				strom.setImageResource(R.drawable.stromanschluss);
				}
		}
		if (cursor.getString(ColumnWasser) != null) {

			if (cursor.getString(ColumnWasser).equals("1")) {
				ImageView strom = (ImageView) view.findViewById(R.id.icon_2);
				strom.setImageResource(R.drawable.frischwasser);
				}
		}
		if (cursor.getString(ColumnChemie) != null) {

			if (cursor.getString(ColumnChemie).equals("1")) {
				ImageView strom = (ImageView) view.findViewById(R.id.icon_3);
				strom.setImageResource(R.drawable.ausguss_chemie_wc);
				}
		}
		if (cursor.getString(ColumnWc) != null) {

			if (cursor.getString(ColumnWc).equals("1")) {
				ImageView strom = (ImageView) view.findViewById(R.id.icon_4);
				strom.setImageResource(R.drawable.wc);
				}
		}
		if (cursor.getString(ColumnDusche) != null) {

			if (cursor.getString(ColumnDusche).equals("1")) {
				ImageView strom = (ImageView) view.findViewById(R.id.icon_5);
				strom.setImageResource(R.drawable.dusche);
				}
		}
		if (cursor.getString(ColumnPreis) != null) {
			ImageView preisres = (ImageView) view.findViewById(R.id.icon_6);
			if (cursor.getInt(ColumnPreis)== 0) {				
				preisres.setImageResource(R.drawable.kreis_gruen);
			}else if (cursor.getInt(ColumnPreis)<= 5) {
				preisres.setImageResource(R.drawable.kreis_gelb);
			}else if (cursor.getInt(ColumnPreis)< 10) {
				preisres.setImageResource(R.drawable.kreis_orange);
			}else if (cursor.getInt(ColumnPreis)>= 10) {
				preisres.setImageResource(R.drawable.kreis_rot);
			}
		}
	}
}
